from flask import jsonify, current_app

from ihome_blue import ihome_blue
from models import House
from utils.response_code import RET


@ihome_blue.route('/houses/<path:id>')
def index(id):
    
    if not id:
        return jsonify(errno=RET.PARAMERR, errmsg='参数异常')

    try:
        house = House.query.get(id)
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg='数据库异常')

    if not house:
        return jsonify(errno=RET.DATAERR, errmsg='没有该数据')

    data = {
        'house' : house.to_full_dict()
    }

    return jsonify(errno=RET.OK, errmsg='查询成功', data=data)
